home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-09-17 | 42.4 KB | 1,480 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: PRShAttr.cpp
- // Release Version: $ ODF 2 $
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "FWOS.hpp"
-
- #ifndef PRSHATTR_H
- #include "PRShAttr.h"
- #endif
-
- #ifndef FWGCONST_H
- #include "FWGConst.h"
- #endif
-
- #ifndef FWWINDIB_H
- #include "FWWinDIB.h"
- #endif
-
- #ifndef FWSTREAM_H
- #include "FWStream.h"
- #endif
-
- #ifndef FWMEMHLP_H
- #include "FWMemHlp.h"
- #endif
-
- #ifndef FWCOLOR_H
- #include "FWColor.h"
- #endif
-
- #ifndef FWEXCEPT_H
- #include "FWExcept.h"
- #endif
-
- //========================================================================================
- // CLASS FW_CPrivPatternRep
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment FWGraphics_PrivPatternRep
- #endif
-
- FW_DEFINE_CLASS_M0(FW_CPrivPatternRep)
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivPatternRep::FW_CPrivPatternRep
- //----------------------------------------------------------------------------------------
-
- FW_CPrivPatternRep::FW_CPrivPatternRep()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivPatternRep::~FW_CPrivPatternRep
- //----------------------------------------------------------------------------------------
-
- FW_CPrivPatternRep::~FW_CPrivPatternRep()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivPatternRep::Write
- //----------------------------------------------------------------------------------------
-
- void FW_CPrivPatternRep::Write(FW_CWritableStream& stream, FW_ClassTypeConstant type, const void *object)
- {
- FW_UNUSED(type);
- FW_CPrivPatternRep* rep = (FW_CPrivPatternRep*) object;
- rep->Flatten(stream);
- }
-
- //========================================================================================
- // CLASS FW_CPrivBWPatternRep
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment FWGraphics_PrivBWPatternRep
- #endif
-
- FW_DEFINE_AUTO(FW_CPrivBWPatternRep)
- FW_DEFINE_CLASS_M1(FW_CPrivBWPatternRep, FW_CPrivPatternRep)
-
- const FW_ClassTypeConstant FW_LPrivBWPatternRep = FW_TYPE_CONSTANT('b','w','p','t');
- FW_REGISTER_ARCHIVABLE_CLASS(FW_LPrivBWPatternRep, FW_CPrivBWPatternRep, FW_CPrivBWPatternRep::Read, 0, 0, FW_CPrivPatternRep::Write)
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivBWPatternRep::FW_CPrivBWPatternRep
- //----------------------------------------------------------------------------------------
-
- FW_CPrivBWPatternRep::FW_CPrivBWPatternRep()
- {
- unsigned char black[8] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
-
- MoveBitPattern(black, &fBitPattern);
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivBWPatternRep::FW_CPrivBWPatternRep
- //----------------------------------------------------------------------------------------
-
- FW_CPrivBWPatternRep::FW_CPrivBWPatternRep(const FW_BitPattern& bits)
- {
- MoveBitPattern(&bits, &fBitPattern);
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivBWPatternRep::FW_CPrivBWPatternRep
- //----------------------------------------------------------------------------------------
-
- FW_CPrivBWPatternRep::FW_CPrivBWPatternRep(FW_CReadableStream& stream)
- {
- stream.Read(fBitPattern.fData, 8);
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivBWPatternRep::~FW_CPrivBWPatternRep
- //----------------------------------------------------------------------------------------
-
- FW_CPrivBWPatternRep::~FW_CPrivBWPatternRep()
- {
- FW_START_DESTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivBWPatternRep::Invert
- //----------------------------------------------------------------------------------------
-
- void FW_CPrivBWPatternRep::Invert()
- {
- *((long*)&fBitPattern.fData[0]) ^= 0xFFFFFFFFL;
- *((long*)&fBitPattern.fData[4]) ^= 0xFFFFFFFFL;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivBWPatternRep::FlipVertically
- //----------------------------------------------------------------------------------------
-
- void FW_CPrivBWPatternRep::FlipVertically()
- {
- for (short i = 0; i<4; i++)
- {
- unsigned char temp = fBitPattern.fData[i];
- fBitPattern.fData[i] = fBitPattern.fData[7-i];
- fBitPattern.fData[7-i] = temp;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivBWPatternRep::FlipHorizontally
- //----------------------------------------------------------------------------------------
- // This is not the best implementation
-
- void FW_CPrivBWPatternRep::FlipHorizontally()
- {
- for (short j = 0; j<8; j++)
- {
- unsigned char leftMask = 0x80;
- unsigned char rightMask = 0x01;
- unsigned char theChar = fBitPattern.fData[j];
- for (short i = 0; i<4; i++)
- {
- unsigned char left = theChar & leftMask;
- unsigned char right = theChar & rightMask;
-
- if (left)
- theChar |= rightMask; // Set
- else
- theChar ^= right; // Clear
-
- if (right)
- theChar |= leftMask; // Set
- else
- theChar ^= left; // Clear
-
- leftMask >>= 1;
- rightMask <<= 1;
- }
- fBitPattern.fData[j] = theChar;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivBWPatternRep::ShiftRight
- //----------------------------------------------------------------------------------------
-
- void FW_CPrivBWPatternRep::ShiftRight()
- {
- for (short i = 0; i<8; i++)
- {
- unsigned char theChar = fBitPattern.fData[i];
- theChar >>= 1;
- if (fBitPattern.fData[i] & 0x01)
- theChar |= 0x80;
- fBitPattern.fData[i] = theChar;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivBWPatternRep::ShiftLeft
- //----------------------------------------------------------------------------------------
-
- void FW_CPrivBWPatternRep::ShiftLeft()
- {
- for (short i = 0; i<8; i++)
- {
- unsigned char theChar = fBitPattern.fData[i];
- theChar <<= 1;
- if (fBitPattern.fData[i] & 0x80)
- theChar |= 0x01;
- fBitPattern.fData[i] = theChar;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivBWPatternRep::ShiftUp
- //----------------------------------------------------------------------------------------
-
- void FW_CPrivBWPatternRep::ShiftUp()
- {
- unsigned char temp = fBitPattern.fData[0];
- for (short i = 0; i<7; i++)
- fBitPattern.fData[i] = fBitPattern.fData[i+1];
- fBitPattern.fData[7] = temp;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivBWPatternRep::ShiftDown
- //----------------------------------------------------------------------------------------
-
- void FW_CPrivBWPatternRep::ShiftDown()
- {
- unsigned char temp = fBitPattern.fData[7];
- for (short i = 7; i>0; i--)
- fBitPattern.fData[i] = fBitPattern.fData[i-1];
- fBitPattern.fData[0] = temp;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivBWPatternRep::IsEqual
- //----------------------------------------------------------------------------------------
-
- FW_Boolean FW_CPrivBWPatternRep::IsEqual(const FW_CPrivPatternRep* other) const
- {
- if (other == this)
- return TRUE;
-
- const FW_CPrivBWPatternRep* patternRep = FW_DYNAMIC_CAST(FW_CPrivBWPatternRep, (FW_CPrivPatternRep*)other);
-
- if (patternRep)
- {
- for (short i=0; i<7; i++)
- if (fBitPattern.fData[i] != patternRep->fBitPattern.fData[i])
- return FALSE;
- return TRUE;
- }
-
- return FALSE;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivBWPatternRep::IsBlack
- //----------------------------------------------------------------------------------------
-
- FW_Boolean FW_CPrivBWPatternRep::IsBlack() const
- {
- return fBitPattern.fDataLongs[0] == 0xFFFFFFFFL && fBitPattern.fDataLongs[1] == 0xFFFFFFFFL;
- }
-
- #ifdef FW_BUILD_WIN
- //----------------------------------------------------------------------------------------
- // FW_CPrivBWPatternRep::WinCreatePatternBrush
- //----------------------------------------------------------------------------------------
-
- HBRUSH FW_CPrivBWPatternRep::WinCreatePatternBrush() const
- {
- unsigned char temp[16]; // 16 because rowbytes has to be even
- for (short i=0; i<8; i++)
- temp[2*i] = fBitPattern.fData[i] ^ 0xFF;
-
- HBRUSH hBrush = NULL;
-
- HBITMAP hbmp = ::CreateBitmap(8, 8, 1, 1, temp);
- if(hbmp != NULL)
- {
- hBrush = ::CreatePatternBrush(hbmp);
- ::DeleteObject(hbmp);
- }
-
- return hBrush;
- }
- #endif
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivBWPatternRep::Copy
- //----------------------------------------------------------------------------------------
-
- FW_CPrivPatternRep* FW_CPrivBWPatternRep::Copy() const
- {
- return FW_NEW(FW_CPrivBWPatternRep, (fBitPattern));
- }
-
- #ifdef FW_BUILD_MAC
- //----------------------------------------------------------------------------------------
- // FW_CPrivBWPatternRep::MacSetInCurPort
- //----------------------------------------------------------------------------------------
-
- void FW_CPrivBWPatternRep::MacSetInCurPort() const
- {
- ::PenPat((const Pattern*)&fBitPattern);
- }
- #endif
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivBWPatternRep::Flatten
- //----------------------------------------------------------------------------------------
-
- void FW_CPrivBWPatternRep::Flatten(FW_CWritableStream& stream) const
- {
- stream.Write(fBitPattern.fData, 8);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivBWPatternRep::Read
- //----------------------------------------------------------------------------------------
-
- void* FW_CPrivBWPatternRep::Read(FW_CReadableStream& stream, FW_ClassTypeConstant type)
- {
- FW_UNUSED(type);
- return FW_NEW(FW_CPrivBWPatternRep, (stream));
- }
-
- //========================================================================================
- // CLASS FW_CPrivColorPatternRep
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment FWGraphics_PrivColorPatternRep
- #endif
-
- FW_DEFINE_AUTO(FW_CPrivColorPatternRep)
- FW_DEFINE_CLASS_M1(FW_CPrivColorPatternRep, FW_CPrivPatternRep)
-
- const FW_ClassTypeConstant FW_LPrivColorPatternRep = FW_TYPE_CONSTANT('c','o','p','t');
- FW_REGISTER_ARCHIVABLE_CLASS(FW_LPrivColorPatternRep, FW_CPrivColorPatternRep, FW_CPrivColorPatternRep::Read, 0, 0, FW_CPrivPatternRep::Write)
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivColorPatternRep::FW_CPrivColorPatternRep
- //----------------------------------------------------------------------------------------
-
- FW_CPrivColorPatternRep::FW_CPrivColorPatternRep(FW_PlatformColorPattern platformColorPattern) :
- fPlatformColorPattern(platformColorPattern)
- {
- FW_ASSERT(fPlatformColorPattern != NULL);
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivColorPatternRep::FW_CPrivColorPatternRep
- //----------------------------------------------------------------------------------------
-
- FW_CPrivColorPatternRep::FW_CPrivColorPatternRep(FW_CReadableStream& stream) :
- fPlatformColorPattern(NULL)
- {
- // Pattern data
- FW_PixelPattern patData;
- stream.Read(patData.fData, sizeof(patData));
-
- // Color count
- unsigned short nbColors;
- stream >> nbColors;
-
- // Colors
- FW_CColor* colors = new FW_CColor[nbColors];
- FW_TRY
- {
- for(int i = 0; i < nbColors; i ++)
- stream >> colors[i];
-
- // Create the pattern
- MakePixelPattern(patData, nbColors, colors);
- }
- FW_CATCH_BEGIN
- FW_CATCH_EVERYTHING()
- {
- delete[] colors;
- FW_THROW_SAME();
- }
- FW_CATCH_END
-
- // Clean up
- delete[] colors;
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivColorPatternRep::FW_CPrivColorPatternRep
- //----------------------------------------------------------------------------------------
-
- FW_CPrivColorPatternRep::FW_CPrivColorPatternRep(const FW_PixelPattern& pixels, short nbColors, const FW_SColor* colorTable) :
- fPlatformColorPattern(NULL)
- {
- #ifdef FW_BUILD_WIN
- fWinCachedBitmap = NULL;
- #endif
-
- MakePixelPattern(pixels, nbColors, colorTable);
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivColorPatternRep::~FW_CPrivColorPatternRep
- //----------------------------------------------------------------------------------------
-
- FW_CPrivColorPatternRep::~FW_CPrivColorPatternRep()
- {
- FW_START_DESTRUCTOR
-
- #ifdef FW_BUILD_MAC
- if (fPlatformColorPattern)
- ::DisposePixPat(fPlatformColorPattern);
- #endif
-
- #ifdef FW_BUILD_WIN
- if (fPlatformColorPattern != NULL)
- FW_DIBFree(fPlatformColorPattern);
-
- WinForgetCachedBitmap();
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivColorPatternRep::IsBlack
- //----------------------------------------------------------------------------------------
-
- FW_Boolean FW_CPrivColorPatternRep::IsBlack() const
- {
- return FALSE;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivColorPatternRep::IsEqual
- //----------------------------------------------------------------------------------------
-
- FW_Boolean FW_CPrivColorPatternRep::IsEqual(const FW_CPrivPatternRep* other) const
- {
- if (other == this)
- return TRUE;
-
- const FW_CPrivColorPatternRep* patternRep = FW_DYNAMIC_CAST(FW_CPrivColorPatternRep, (FW_CPrivPatternRep*)other);
- if (patternRep == NULL)
- return FALSE;
-
- // Compare the pixels
- FW_PixelPattern pixData1;
- GetPixelData(pixData1);
-
- FW_PixelPattern pixData2;
- patternRep->GetPixelData(pixData2);
-
- if(::memcmp(pixData1.fData, pixData2.fData, sizeof(FW_PixelPattern)) != 0)
- return FALSE;
-
- // Compare the color tables
- FW_SColor* colors1 = NULL;
- unsigned short nbColors1 = GetColorTable(colors1);
-
- FW_SColor* colors2 = NULL;
- unsigned short nbColors2 = patternRep->GetColorTable(colors2);
-
- if(nbColors1 != nbColors2 || ::memcmp(colors1, colors2, sizeof(FW_SColor) * nbColors1) != 0)
- {
- delete[] colors1;
- delete[] colors2;
- return FALSE;
- }
-
- return TRUE;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivColorPatternRep::Copy
- //----------------------------------------------------------------------------------------
-
- FW_CPrivPatternRep* FW_CPrivColorPatternRep::Copy() const
- {
- FW_PlatformColorPattern platformColorPattern;
-
- #ifdef FW_BUILD_MAC
- platformColorPattern = ::NewPixPat();
- ::CopyPixPat(fPlatformColorPattern, platformColorPattern);
- #endif
-
- #ifdef FW_BUILD_WIN
- platformColorPattern = FW_DIBCreateCopy(fPlatformColorPattern);
- #endif
-
- return FW_NEW(FW_CPrivColorPatternRep, (platformColorPattern));
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivColorPatternRep::Flatten
- //----------------------------------------------------------------------------------------
-
- void FW_CPrivColorPatternRep::Flatten(FW_CWritableStream& stream) const
- {
- // Pixel data
- FW_PixelPattern pixData;
- GetPixelData(pixData);
- stream.Write(pixData.fData, sizeof(pixData));
-
- // ----- Colors
- FW_SColor* colors = NULL;
- unsigned short nbColors = GetColorTable(colors);
- FW_TRY
- {
- stream << nbColors;
- for(int i = 0; i < nbColors; i++)
- stream << FW_CColor(colors[i]); // [HLX] added the cast
- }
- FW_CATCH_BEGIN
- FW_CATCH_EVERYTHING()
- {
- // Clean up
- delete[] colors;
-
- FW_THROW_SAME();
- }
- FW_CATCH_END
-
- // Clean up
- delete[] colors;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivColorPatternRep::Invert
- //----------------------------------------------------------------------------------------
-
- void FW_CPrivColorPatternRep::Invert()
- {
- // Get current pattern info
- FW_PixelPattern pixData;
- GetPixelData(pixData);
-
- // ----- Look for minimum and maximun -----
- unsigned char max = 0x00;
- int i;
-
- for (i = 0; i < 8 * 8; i++)
- {
- unsigned char c = pixData.fDataRaw[i];
- if (c > max)
- max = c;
- }
-
- // ----- Invert it -----
- for (i = 0; i < 8 * 8; i++)
- pixData.fDataRaw[i] = max - pixData.fDataRaw[i];
-
- // Update the pattern
- SetPixelData(pixData);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivColorPatternRep::FlipVertically
- //----------------------------------------------------------------------------------------
-
- void FW_CPrivColorPatternRep::FlipVertically()
- {
- // Get current pattern info
- FW_PixelPattern pixData;
- GetPixelData(pixData);
-
- // Flip it
- for (short i = 0; i < 4; i++)
- for (short j = 0; j < 2; j++)
- {
- unsigned long l = pixData.fDataLongs[i][j];
- pixData.fDataLongs[i][j] = pixData.fDataLongs[7 - i][j];
- pixData.fDataLongs[7 - i][j] = l;
- }
-
- // Update the pattern
- SetPixelData(pixData);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivColorPatternRep::FlipHorizontally
- //----------------------------------------------------------------------------------------
-
- void FW_CPrivColorPatternRep::FlipHorizontally()
- {
- // Get current pattern info
- FW_PixelPattern pixData;
- GetPixelData(pixData);
-
- // Flip it
- for (short i = 0; i < 8; i++)
- for (short j = 0; j < 4; j++)
- {
- unsigned char c = pixData.fData[i][j];
- pixData.fData[i][j] = pixData.fData[i][7 - j];
- pixData.fData[i][7 - j] = c;
- }
-
- // Update the pattern
- SetPixelData(pixData);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivColorPatternRep::ShiftRight
- //----------------------------------------------------------------------------------------
-
- void FW_CPrivColorPatternRep::ShiftRight()
- {
- // Get current pattern info
- FW_PixelPattern pixData;
- GetPixelData(pixData);
-
- // Shift it
- for (short i = 0; i < 8; i++)
- {
- unsigned char c = pixData.fData[i][7];
- for(short j = 7; j > 0; j--)
- pixData.fData[i][j] = pixData.fData[i][j - 1];
- pixData.fData[i][0] = c;
- }
-
- // Update the pattern
- SetPixelData(pixData);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivColorPatternRep::ShiftLeft
- //----------------------------------------------------------------------------------------
-
- void FW_CPrivColorPatternRep::ShiftLeft()
- {
- // Get current pattern info
- FW_PixelPattern pixData;
- GetPixelData(pixData);
-
- // Shift it
- for (short i = 0; i < 8; i++)
- {
- unsigned char c = pixData.fData[i][0];
- for(short j = 0; j < 7; j++)
- pixData.fData[i][j] = pixData.fData[i][j + 1];
- pixData.fData[i][7] = c;
- }
-
- // Update the pattern
- SetPixelData(pixData);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivColorPatternRep::ShiftUp
- //----------------------------------------------------------------------------------------
-
- void FW_CPrivColorPatternRep::ShiftUp()
- {
- // Get current pattern info
- FW_PixelPattern pixData;
- GetPixelData(pixData);
-
- // Shift it
- unsigned long temp0 = pixData.fDataLongs[0][0];
- unsigned long temp1 = pixData.fDataLongs[0][1];
-
- for (short i = 0; i < 7; i++)
- {
- pixData.fDataLongs[i][0] = pixData.fDataLongs[i + 1][0];
- pixData.fDataLongs[i][1] = pixData.fDataLongs[i + 1][1];
- }
-
- pixData.fDataLongs[7][0] = temp0;
- pixData.fDataLongs[7][1] = temp1;
-
- // Update the pattern
- SetPixelData(pixData);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivColorPatternRep::ShiftDown
- //----------------------------------------------------------------------------------------
-
- void FW_CPrivColorPatternRep::ShiftDown()
- {
- // Get current pattern info
- FW_PixelPattern pixData;
- GetPixelData(pixData);
-
- // Shift it
- unsigned long temp0 = pixData.fDataLongs[7][0];
- unsigned long temp1 = pixData.fDataLongs[7][1];
-
- for (short i = 7; i > 0; i--)
- {
- pixData.fDataLongs[i][0] = pixData.fDataLongs[i - 1][0];
- pixData.fDataLongs[i][1] = pixData.fDataLongs[i - 1][1];
- }
-
- pixData.fDataLongs[0][0] = temp0;
- pixData.fDataLongs[0][1] = temp1;
-
- // Update the pattern
- SetPixelData(pixData);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivColorPatternRep::Read
- //----------------------------------------------------------------------------------------
-
- void* FW_CPrivColorPatternRep::Read(FW_CReadableStream& stream, FW_ClassTypeConstant type)
- {
- FW_UNUSED(type);
- return FW_NEW(FW_CPrivColorPatternRep, (stream));
- }
-
- #ifdef FW_BUILD_MAC
- //----------------------------------------------------------------------------------------
- // FW_CPrivColorPatternRep::MacSetInCurPort
- //----------------------------------------------------------------------------------------
-
- void FW_CPrivColorPatternRep::MacSetInCurPort() const
- {
- FW_ASSERT(fPlatformColorPattern != NULL);
-
- // FW_PlatformColorPattern platformColorPattern = ::NewPixPat();
- // ::CopyPixPat(fPlatformColorPattern, platformColorPattern);
- // ::PenPixPat(platformColorPattern);
- // [HLX] We should not have to make a copy. Quickdraw won't dispose it. If we dispose it
- // Quickdraw will reset the 'standard pattern'
- ::PenPixPat(fPlatformColorPattern);
- }
- #endif
-
- #ifdef FW_BUILD_WIN
- //----------------------------------------------------------------------------------------
- // FW_CPrivColorPatternRep::WinCreatePatternBrush
- //----------------------------------------------------------------------------------------
-
- HBRUSH FW_CPrivColorPatternRep::WinCreatePatternBrush() const
- {
- HBRUSH hBrush = NULL;
-
- // Convert into a DDB for effeciency
- if (fWinCachedBitmap == NULL)
- ((FW_CPrivColorPatternRep*) this)->fWinCachedBitmap = FW_DIBConvertToBitmap(fPlatformColorPattern, NULL);
-
- // Create the brush
- if(fWinCachedBitmap != NULL)
- hBrush = ::CreatePatternBrush(fWinCachedBitmap);
-
- return hBrush;
- }
- #endif
-
- #ifdef FW_BUILD_WIN
- //----------------------------------------------------------------------------------------
- // FW_CPrivColorPatternRep::WinForgetCachedBitmap
- //----------------------------------------------------------------------------------------
-
- void FW_CPrivColorPatternRep::WinForgetCachedBitmap()
- {
- if (fWinCachedBitmap != NULL)
- {
- ::DeleteObject(fWinCachedBitmap);
- fWinCachedBitmap = NULL;
- }
- }
- #endif
-
- #ifdef FW_BUILD_MAC
- //----------------------------------------------------------------------------------------
- // FW_CPrivColorPatternRep::MacNewPixPat
- //----------------------------------------------------------------------------------------
-
- PixPatHandle FW_CPrivColorPatternRep::MacNewPixPat(const void* pixels,
- short rowBytes, short pixelSize,
- short withPower, short heightPower,
- short nbColors, const FW_SColor* colorTable)
- {
- FW_ASSERT(pixels != NULL);
- FW_ASSERT(colorTable != NULL);
- FW_ASSERT((rowBytes & 0x0001) == 0);
- FW_ASSERT(pixelSize == 1 || pixelSize == 2 || pixelSize == 4 || pixelSize == 8);
- FW_ASSERT(withPower != 0);
- FW_ASSERT(heightPower != 0);
- FW_ASSERT(nbColors <= (1 << pixelSize));
-
- PixPatHandle pixPat = ::NewPixPat();
-
- (*pixPat)->patType = 1;
-
- // ----- Creates the pixMap -----
- PixMapHandle pixMap = (*pixPat)->patMap;
-
- (*pixMap)->rowBytes = rowBytes | 0x8000;
- (*pixMap)->bounds.left = 0;
- (*pixMap)->bounds.top = 0;
- (*pixMap)->bounds.right = 1 << withPower;
- (*pixMap)->bounds.bottom = 1 << heightPower;
- (*pixMap)->pixelSize = pixelSize;
- (*pixMap)->cmpCount = 1;
- (*pixMap)->cmpSize = pixelSize;
-
- // ----- Set up the color table -----
- CTabHandle hColors = (*pixMap)->pmTable;
- Size colorTabSize = sizeof(ColorTable) + (nbColors * sizeof(ColorSpec));
- ::SetHandleSize((Handle)hColors, colorTabSize);
-
- ::HLock((Handle)hColors);
- CTabPtr pColors = *hColors;
- pColors->ctSeed = ::GetCTSeed();
- pColors->ctFlags = 0;
- pColors->ctSize = nbColors - 1;
-
- for (short i = 0; i<nbColors; i++)
- {
- pColors->ctTable[i].value = i;
- FW_MacColorToRGB(colorTable[i], &pColors->ctTable[i].rgb);
- }
- ::HUnlock((Handle)hColors);
-
- // ----- Creates the pattern data -----
- Size dataSize = (Size)rowBytes * 8;
- Handle patData = (*pixPat)->patData;
- ::SetHandleSize(patData, dataSize);
-
- ::HLock(patData);
- ::BlockMove(pixels, *patData, dataSize);
- ::HUnlock(patData);
-
- return pixPat;
- }
- #endif
-
- #ifdef FW_BUILD_WIN
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivColorPatternRep::WinFlipPixelCopy
- //----------------------------------------------------------------------------------------
-
- void FW_CPrivColorPatternRep::WinFlipPixelCopy(const void* source, void* dest)
- {
- unsigned long* sourceL = (unsigned long*) source;
- unsigned long* destL = (unsigned long*) dest;
-
- for(int i = 0; i < 16; i += 2)
- {
- destL[14 - i] = sourceL[i];
- destL[15 - i] = sourceL[i + 1];
- }
- }
-
- #endif
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivColorPatternRep::MakePixelPattern
- //----------------------------------------------------------------------------------------
-
- void FW_CPrivColorPatternRep::MakePixelPattern(const FW_PixelPattern& pixels, short nbColors, const FW_SColor* colorTable)
- {
- #ifdef FW_BUILD_MAC
- fPlatformColorPattern = MacNewPixPat(pixels.fData, 8, 8, 3, 3, nbColors, colorTable);
- #endif
-
- #ifdef FW_BUILD_WIN
- // We need to flip the bits because DIBs are stored bottom-to-top
- FW_PixelPattern pixData;
- WinFlipPixelCopy(pixels.fData, pixData.fData);
-
- // Create the DIB
- fPlatformColorPattern = FW_DIBCreate(8, 8, 8, nbColors, colorTable, pixData.fData);
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivColorPatternRep::GetPixelData
- //----------------------------------------------------------------------------------------
-
- void FW_CPrivColorPatternRep::GetPixelData(FW_PixelPattern& pixData) const
- {
- #ifdef FW_BUILD_MAC
- Handle patData = (*fPlatformColorPattern)->patData;
-
- ::HLock(patData);
- BlockMove((FW_PixelPattern*)*patData, pixData.fDataRaw, 64);
- ::HUnlock(patData);
- #endif
- #ifdef FW_BUILD_WIN
- FW_WinPixelBufferPtr pixels = FW_DIBGetPixelBuffer(fPlatformColorPattern);
- WinFlipPixelCopy(pixels, pixData.fData);
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivColorPatternRep::SetPixelData
- //----------------------------------------------------------------------------------------
-
- void FW_CPrivColorPatternRep::SetPixelData(const FW_PixelPattern& pixData)
- {
- #ifdef FW_BUILD_MAC
- Handle patData = (*fPlatformColorPattern)->patData;
-
- ::HLock(patData);
- ::BlockMove(pixData.fDataRaw, (FW_PixelPattern*)*patData, 64);
- ::HUnlock(patData);
-
- ::PixPatChanged(fPlatformColorPattern);
- #endif
- #ifdef FW_BUILD_WIN
- FW_WinPixelBufferPtr pixels = FW_DIBGetPixelBuffer(fPlatformColorPattern);
- WinFlipPixelCopy(pixData.fData, pixels);
-
- WinForgetCachedBitmap();
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivColorPatternRep::GetColorTable
- //----------------------------------------------------------------------------------------
-
- unsigned short FW_CPrivColorPatternRep::GetColorTable(FW_SColor*& colors) const
- {
- #ifdef FW_BUILD_MAC
- PixMapHandle pixMap = (*fPlatformColorPattern)->patMap;
-
- CTabHandle hColors = (*pixMap)->pmTable;
- FW_CAcquireLockedSystemHandle lock((FW_PlatformHandle)hColors);
- CTabPtr pColors = *hColors;
-
- unsigned short nbColors = pColors->ctSize + 1;
- colors = new FW_SColor[nbColors];
- for (unsigned short i = 0; i<nbColors; i++)
- colors[i] = FW_MacRGBToColor(&pColors->ctTable[i].rgb);
-
- return nbColors;
- #endif
- #ifdef FW_BUILD_WIN
- FW_SColor* rgbColors = NULL;
- unsigned short nColors = FW_DIBAcquireColorTable(fPlatformColorPattern, &rgbColors);
-
- // Convert RGB colors to C++ colors
- colors = new FW_SColor[nColors];
- for (unsigned short i = 0; i < nColors; ++ i)
- colors[i] = rgbColors[i];
-
- FW_DIBReleaseColorTable(rgbColors);
-
- return nColors;
- #endif
- }
-
- //========================================================================================
- // class FW_CPrivInkRep
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment FWGraphics_PrivInkRep
- #endif
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivInkRep::FW_CPrivInkRep
- //----------------------------------------------------------------------------------------
-
- FW_CPrivInkRep::FW_CPrivInkRep(FW_SColor fore, FW_SColor back, FW_TransferModes mode):
- fForeColor(fore),
- fBackColor(back),
- fTransferMode(mode)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivInkRep::FW_CPrivInkRep
- //----------------------------------------------------------------------------------------
-
- FW_CPrivInkRep::FW_CPrivInkRep(FW_EStandardInks std) :
- fForeColor(FW_kRGBBlack),
- fBackColor(FW_kRGBWhite)
- {
- switch (std)
- {
- default:
- case FW_kNormalInk:
- fTransferMode = FW_kCopy;
- break;
-
- case FW_kNormalTextInk:
- fTransferMode = FW_kOr;
- break;
-
- case FW_kInvertInk:
- fTransferMode = FW_kInvert;
- break;
-
- case FW_kWhiteEraseInk:
- fTransferMode = FW_kErase;
- break;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivInkRep::FW_CPrivInkRep
- //----------------------------------------------------------------------------------------
-
- FW_CPrivInkRep::FW_CPrivInkRep(const FW_CPrivInkRep& otherRep):
- fForeColor(otherRep.fForeColor),
- fBackColor(otherRep.fBackColor),
- fTransferMode(otherRep.fTransferMode)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivInkRep::FW_CPrivInkRep
- //----------------------------------------------------------------------------------------
-
- FW_CPrivInkRep::FW_CPrivInkRep(FW_CReadableStream& stream)
- {
- stream >> fForeColor;
- stream >> fBackColor;
- stream >> fTransferMode;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivInkRep::~FW_CPrivInkRep
- //----------------------------------------------------------------------------------------
-
- FW_CPrivInkRep::~FW_CPrivInkRep()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivInkRep::IsEqual
- //----------------------------------------------------------------------------------------
-
- FW_Boolean FW_CPrivInkRep::IsEqual(const FW_CPrivInkRep* other) const
- {
- if (other == this)
- return TRUE;
-
- return fTransferMode == other->fTransferMode &&
- fForeColor == other->fForeColor &&
- fBackColor == other->fBackColor;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivInkRep::Write
- //----------------------------------------------------------------------------------------
-
- void FW_CPrivInkRep::Write(FW_CWritableStream& stream) const
- {
- stream << fForeColor;
- stream << fBackColor;
- stream << fTransferMode;
- }
-
- //========================================================================================
- // class FW_CPrivStyleRep
- //========================================================================================
-
- FW_DEFINE_AUTO(FW_CPrivStyleRep)
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivStyleRep::FW_CPrivStyleRep
- //----------------------------------------------------------------------------------------
-
- FW_CPrivStyleRep::FW_CPrivStyleRep(FW_Fixed penSize, FW_EStyleDash dash) :
- fPenSize(penSize),
- fDash(dash),
- fPattern(FW_NEW(FW_CPrivBWPatternRep, ()))
- {
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivStyleRep::FW_CPrivStyleRep
- //----------------------------------------------------------------------------------------
-
- FW_CPrivStyleRep::FW_CPrivStyleRep(FW_Fixed penSize, FW_HPattern pattern) :
- fPenSize(penSize),
- fDash(FW_kSolidLine),
- fPattern(pattern)
- {
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivStyleRep::FW_CPrivStyleRep
- //----------------------------------------------------------------------------------------
-
- FW_CPrivStyleRep::FW_CPrivStyleRep(FW_CReadableStream& stream)
- {
- stream >> fPenSize;
-
- short nDash;
- stream >> nDash;
- fDash = (FW_EStyleDash) nDash;
-
- FW_CPrivPatternRep* pattern;
- FW_READ_DYNAMIC_OBJECT(stream, &pattern, FW_CPrivPatternRep);
- fPattern = pattern;
-
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivStyleRep::FW_CPrivStyleRep
- //----------------------------------------------------------------------------------------
-
- FW_CPrivStyleRep::FW_CPrivStyleRep(FW_EStandardStyles std) :
- fPenSize(FW_kFixedPos1),
- fPattern(FW_NEW(FW_CPrivBWPatternRep, ()))
- {
- switch(std)
- {
- default:
- FW_ASSERT(FALSE); // Invalid standard style
- // fall-through
- case FW_kNormalStyle:
- fDash = FW_kSolidLine;
- break;
-
- case FW_kDashStyle:
- fDash = FW_kDash;
- break;
-
- case FW_kDotStyle:
- fDash = FW_kDot;
- break;
-
- case FW_kDashDotStyle:
- fDash = FW_kDashDot;
- break;
-
- case FW_kDashDotDotStyle:
- fDash = FW_kDashDotDot;
- break;
- }
-
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivStyleRep::FW_CPrivStyleRep
- //----------------------------------------------------------------------------------------
-
- FW_CPrivStyleRep::FW_CPrivStyleRep(const FW_CPrivStyleRep& otherRep) :
- fPenSize (otherRep.fPenSize),
- fDash (otherRep.fDash),
- fPattern (otherRep.fPattern)
- {
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivStyleRep::~FW_CPrivStyleRep
- //----------------------------------------------------------------------------------------
-
- FW_CPrivStyleRep::~FW_CPrivStyleRep()
- {
- FW_START_DESTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivStyleRep::GetUnSharedPattern
- //----------------------------------------------------------------------------------------
-
- FW_HPattern FW_CPrivStyleRep::GetUnSharedPattern()
- {
- if (fPattern->GetRefCount() > 1)
- fPattern = fPattern->Copy();
-
- return fPattern;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivStyleRep::Write
- //----------------------------------------------------------------------------------------
-
- void FW_CPrivStyleRep::Write(FW_CWritableStream& stream) const
- {
- stream << fPenSize;
- stream << (short) fDash;
-
- const FW_CPrivPatternRep* rep = fPattern;
- FW_WRITE_DYNAMIC_OBJECT(stream, rep, FW_CPrivPatternRep);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivStyleRep::IsEqual
- //----------------------------------------------------------------------------------------
-
- FW_Boolean FW_CPrivStyleRep::IsEqual(const FW_CPrivStyleRep* other) const
- {
- if (other == this)
- return TRUE;
-
- return fPenSize == other->fPenSize &&
- fDash == other->fDash &&
- fPattern->IsEqual(other->fPattern);
- }
-
- //========================================================================================
- // class FW_CPrivFontRep
- //========================================================================================
-
- FW_DEFINE_AUTO(FW_CPrivFontRep)
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivFontRep::FW_CPrivFontRep
- //----------------------------------------------------------------------------------------
-
- FW_CPrivFontRep::FW_CPrivFontRep() :
- fFontStyle(FW_kPlain),
- fFontSize(FW_IntToFixed(12)),
- fFontName()
- #ifdef FW_BUILD_MAC
- ,fMacValidCache(FALSE)
- #endif
- {
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivFontRep::FW_CPrivFontRep
- //----------------------------------------------------------------------------------------
-
- FW_CPrivFontRep::FW_CPrivFontRep(const FW_CString& fontName, FW_FontStyle fontStyle, FW_Fixed fontSize) :
- fFontStyle(fontStyle),
- fFontSize(fontSize),
- fFontName(fontName)
- #ifdef FW_BUILD_MAC
- ,fMacValidCache(FALSE)
- #endif
- {
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivFontRep::FW_CPrivFontRep
- //----------------------------------------------------------------------------------------
-
- FW_CPrivFontRep::FW_CPrivFontRep(const FW_CPrivFontRep& otherRep):
- fFontStyle(otherRep.fFontStyle),
- fFontSize(otherRep.fFontSize),
- fFontName(otherRep.fFontName)
- #ifdef FW_BUILD_MAC
- ,fMacValidCache(FALSE)
- #endif
- {
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivFontRep::FW_CPrivFontRep
- //----------------------------------------------------------------------------------------
-
- FW_CPrivFontRep::FW_CPrivFontRep(FW_CReadableStream& stream)
- #ifdef FW_BUILD_MAC
- : fMacValidCache(FALSE)
- #endif
- {
- stream >> fFontSize;
- stream >> fFontStyle;
- stream >> fFontName;
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivFontRep::FW_CPrivFontRep
- //----------------------------------------------------------------------------------------
-
- FW_CPrivFontRep::FW_CPrivFontRep(FW_EStandardFonts std) :
- fFontSize(FW_IntToFixed(12)),
- fFontStyle(FW_kPlain)
- #ifdef FW_BUILD_MAC
- , fMacValidCache(FALSE)
- #endif
- {
- switch (std)
- {
- case FW_kNormalFont:
- fFontName = FW_GetDefaultFontName();
- #ifdef FW_BUILD_MAC
- fFontSize = FW_IntToFixed(::GetDefFontSize());
- #endif
- #ifdef FW_BUILD_WIN
- FW_DEBUG_MESSAGE("FW_CPrivFontRep::FW_CPrivFontRep");
- #endif
- break;
- case FW_kSystemFont:
- fFontName = FW_GetSystemFontName();
- #ifdef FW_BUILD_MAC
- fFontSize = FW_IntToFixed(::GetDefFontSize());
- #endif
- #ifdef FW_BUILD_WIN
- FW_DEBUG_MESSAGE("FW_CPrivFontRep::FW_CPrivFontRep");
- #endif
- break;
- case FW_kHelvetica12:
- fFontName = FW_GetHelveticaFontName();
- break;
- case FW_kTimes12:
- fFontName = FW_GetTimesFontName();
- break;
- case FW_kPalatino12:
- fFontName = FW_GetPalatinoFontName();
- break;
- case FW_kCourier12:
- fFontName = FW_GetCourierFontName();
- break;
- }
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivFontRep::~FW_CPrivFontRep
- //----------------------------------------------------------------------------------------
-
- FW_CPrivFontRep::~FW_CPrivFontRep()
- {
- FW_START_DESTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivFontRep::SetFontName
- //----------------------------------------------------------------------------------------
-
- void FW_CPrivFontRep::SetFontName(const FW_CString& fontName)
- {
- fFontName = fontName;
- #ifdef FW_BUILD_MAC
- fMacValidCache = FALSE;
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivFontRep::SetFontStyle
- //----------------------------------------------------------------------------------------
-
- void FW_CPrivFontRep::SetFontStyle(FW_FontStyle fontStyle)
- {
- fFontStyle = fontStyle;
- #ifdef FW_BUILD_MAC
- fMacValidCache = FALSE;
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivFontRep::Write
- //----------------------------------------------------------------------------------------
-
- void FW_CPrivFontRep::Write(FW_CWritableStream& stream) const
- {
- stream << fFontSize;
- stream << fFontStyle;
- stream << fFontName;
- }
-
- #ifdef FW_BUILD_MAC
- //----------------------------------------------------------------------------------------
- // FW_CPrivFontRep::MacGetFontID
- //----------------------------------------------------------------------------------------
-
- short FW_CPrivFontRep::MacGetFontID() const
- {
- ((FW_CPrivFontRep*)this)->MacCheckFontCache();
- return fMacFontID;
- }
- #endif
-
- #ifdef FW_BUILD_MAC
- //----------------------------------------------------------------------------------------
- // FW_CPrivFontRep::MacGetFontStyle
- //----------------------------------------------------------------------------------------
-
- Style FW_CPrivFontRep::MacGetFontStyle() const
- {
- ((FW_CPrivFontRep*)this)->MacCheckFontCache();
- return fMacFontStyle;
- }
- #endif
-
- #ifdef FW_BUILD_MAC
- //----------------------------------------------------------------------------------------
- // FW_CPrivFontRep::MacSetFontID
- //----------------------------------------------------------------------------------------
-
- void FW_CPrivFontRep::MacSetFontID(short macFontID)
- {
- FW_CString255 fontName;
-
- if (macFontID == 0)
- fontName = FW_GetSystemFontName();
- else if (macFontID == 1)
- fontName = FW_GetDefaultFontName();
- else
- {
- Str255 pstr;
- ::GetFontName(macFontID, pstr);
- fontName.Append((char*)&pstr[1], pstr[0]);
- }
- SetFontName(fontName);
- }
- #endif
-
- #ifdef FW_BUILD_MAC
- //----------------------------------------------------------------------------------------
- // FW_CPrivFontRep::MacCheckFontCache
- //----------------------------------------------------------------------------------------
-
- void FW_CPrivFontRep::MacCheckFontCache()
- {
- if (!fMacValidCache)
- {
- fMacFontStyle = normal;
- if (fFontStyle & FW_kBold)
- fMacFontStyle += bold;
- if (fFontStyle & FW_kItalic)
- fMacFontStyle += italic;
- if (fFontStyle & FW_kUnderline)
- fMacFontStyle += underline;
- if (fFontStyle & FW_kStrikeOut)
- fMacFontStyle += normal;
- if (fFontStyle & FW_kOutline)
- fMacFontStyle += outline;
- if (fFontStyle & FW_kShadow)
- fMacFontStyle += shadow;
- if (fFontStyle & FW_kExtended)
- fMacFontStyle += extend;
- if (fFontStyle & FW_kCondensed)
- fMacFontStyle += condense;
-
- // ----- fMacFontID -----
-
- // Special case of System and Application Fonts
- if (fFontName == FW_GetSystemFontName())
- fMacFontID = 0;
- else if (fFontName == FW_GetDefaultFontName())
- fMacFontID = 1;
- else
- {
- short fontNumber;
- Str255 pascalFontName;
-
- fFontName.ExportPascal(pascalFontName);
- ::GetFNum(pascalFontName, &fontNumber);
- fMacFontID = fontNumber;
- }
- fMacValidCache = TRUE;
- }
- }
-
- #endif
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivFontRep::IsEqual
- //----------------------------------------------------------------------------------------
-
- FW_Boolean FW_CPrivFontRep::IsEqual(const FW_CPrivFontRep* other) const
- {
- if (other == this)
- return TRUE;
-
- return
- fFontStyle == other->fFontStyle &&
- fFontSize == other->fFontSize &&
- fFontName == other->fFontName;
- }
-
-